package com.st.shopadmin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.st.shopadmin.common.ServerResponse;
import com.st.shopadmin.dao.BuyerInfoMapper;
import com.st.shopadmin.pojo.BuyerInfo;
import com.st.shopadmin.pojo.BuyerTaoBaoInfo;
import com.st.shopadmin.pojo.BuyerUserInfo;
import com.st.shopadmin.pojo.ShopUserPlat;
import com.st.shopadmin.service.BuyerService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BuyerServiceImpl implements BuyerService{
    @Autowired
    private BuyerInfoMapper buyerInfoMapper;

    @Override
    public ServerResponse<List> getBuyerLists(int pageNum, int pageSize) {
        /*List<BuyerInfo> buyerLists = buyerInfoMapper.selectList();*/
        List<BuyerUserInfo> buyerLists = buyerInfoMapper.selectBuyerUserInfoList();
        return  ServerResponse.createBySuccess(buyerLists);
    }

    @Override
    public ServerResponse<PageInfo> getBuyerPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        /*List<BuyerInfo> buyerLists = buyerInfoMapper.selectList();*/
        List<BuyerUserInfo> buyerLists = buyerInfoMapper.selectBuyerUserInfoList();
        PageInfo pageResult = new PageInfo(buyerLists);
        return  ServerResponse.createBySuccess(pageResult);
    }

    @Override
    public ServerResponse<BuyerInfo> getBuyerDetail(Long buyerId) {
            if(buyerId == null){
                return  ServerResponse.createByErrorMessage("参数错误");
            }
        BuyerInfo buyerInfo = buyerInfoMapper.selectByPrimaryKey(buyerId);
            if(buyerInfo == null){
                return  ServerResponse.createByErrorMessage("不存在");
            }
            return  ServerResponse.createBySuccess(buyerInfo);
    }

    @Override
    public ServerResponse<BuyerTaoBaoInfo> taoBaoCheckDetail(Long buyerId) {
        if(buyerId == null){
            return  ServerResponse.createByErrorMessage("参数错误");
        }
        BuyerTaoBaoInfo buyerTaoBaoInfo = buyerInfoMapper.selectByBuyerId(buyerId);
        if(buyerTaoBaoInfo == null){
            return  ServerResponse.createByErrorMessage("不存在");
        }
        return  ServerResponse.createBySuccess(buyerTaoBaoInfo);
    }

    @Override
    public ServerResponse updateBuyerStatus(Long buyerId, Integer idStatus,String idNopassReason) {
        if(idStatus == null || buyerId == null){
            return   ServerResponse.createByErrorMessage("参数错误");
        }
        BuyerInfo buyerInfo = new BuyerInfo();
        buyerInfo.setUid(buyerId);
        buyerInfo.setIdStatus(idStatus);
        buyerInfo.setIdNopassReason(idNopassReason);
        int rowCount  = buyerInfoMapper.updateByPrimaryKeySelective(buyerInfo);
        if(rowCount > 0){
            return  ServerResponse.createBySuccess("更新成功");
        }
        return ServerResponse.createByErrorMessage("更新失败");
    }

    @Override
    public ServerResponse updateTaoBaoStatus(Long buyerId, Integer taoBaoStatus,String taobaoNopassReason) {
        if(taoBaoStatus == null || buyerId == null){
            return   ServerResponse.createByErrorMessage("参数错误");
        }
        BuyerInfo buyerInfo = new BuyerInfo();
        buyerInfo.setUid(buyerId);
        buyerInfo.setTaobaoStatus(taoBaoStatus);
        buyerInfo.setTaobaoNopassReason(taobaoNopassReason);
        int rowCount  = buyerInfoMapper.updateByPrimaryKeySelective(buyerInfo);
        if(rowCount > 0){
            return  ServerResponse.createBySuccess("更新成功");
        }
        return ServerResponse.createByErrorMessage("更新失败");
    }

    @Override
    public ServerResponse stopStatus(Long buyerId,String stopReason) {
        if(stopReason == null || buyerId == null){
            return   ServerResponse.createByErrorMessage("参数错误");
        }
        BuyerInfo buyerInfo = new BuyerInfo();
        buyerInfo.setUid(buyerId);
        buyerInfo.setStatus(1);
        buyerInfo.setStopReason(stopReason);
        int rowCount  = buyerInfoMapper.updateByPrimaryKeySelective(buyerInfo);
        if(rowCount > 0){
            return  ServerResponse.createBySuccess("更新成功");
        }
        return ServerResponse.createByErrorMessage("更新失败");
    }

    @Override
    public ServerResponse<List> searchLists(BuyerUserInfo buyerUserInfo,int pageNum,int pageSize){
        List<BuyerUserInfo> productList = buyerInfoMapper.searchLists(buyerUserInfo);
        return  ServerResponse.createBySuccess(productList);
    }


}
